package fun.xinnix.controller;

import fun.xinnix.entity.Result;
import fun.xinnix.service.AuthService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    AuthService authService;

    @PostMapping("/shiroLogin")
    public Result shiroLogin(@RequestBody @Valid AuthParam param) {
        return Result.success(authService.shiroLogin(param.getUserName(), param.getPassword()));
    }

    @PostMapping("/login")
    public Result login(@RequestBody @Valid AuthParam param) {
        return Result.success(authService.login(param.getUserName(), param.getPassword()));
    }

    @Data
    static class AuthParam {
        @NotBlank(message = "请输入账号")
        private String userName;

        @NotBlank(message = "请输入密码")
        private String password;
    }
}

